#include "../include/kasm.h"
#include "../include/kc.h"
#include "../include/defs.h"
#include "../include/syscalls.h"

//systemcall de lectura
int
read(int fd, char * buffer, int count, int flags){
	return _syscall(READFILE, fd, count, flags, buffer, NULL);
}

//systemcall de escritura
int
write(int fd, char * buffer, int count, int flags){
	return _syscall(WRITEFILE, fd, count, flags, buffer, NULL);
}

//systemcall para ceder el procesador
int
yield(){
	return _syscall(YIELD, 0, 0, 0, NULL, NULL);
}

//systemcall para crear nuevos procesos
int
startProcess(int (*process)(int,char**), char * procName, char isBackground,
	int argc, char ** argv, unsigned char priority) {

	stProcessAux processAux;
	processAux.procName = procName;
	processAux.process = process;

	return _syscall(ST_PROCESS, priority, isBackground, argc,
			(char*)argv, (char*)&processAux);
}

void
waitPid(int pid){
	_syscall(WAIT, pid, 0, 0, NULL, NULL);
}

void
kill(int pid){
	_syscall(KILL, pid, 0, 0, NULL, NULL);
}

int
getProcs(void * procs, int maxProcs){
	return _syscall(GET_PROC, maxProcs, 0, 0, procs, NULL);
}

int
debugCall(){
	return _syscall(DEBUG_CALL, 0, 0, 0, NULL, NULL);
}

int
getVideoXY(int * x, int * y){
	//0 es hacer un get
	return _syscall(VIDEO_POS, 0, (int)x, (int)y, NULL, NULL);
}

int
setVideoXY(int x, int y){
	//1 es hacer un set
	return _syscall(VIDEO_POS, 1, x, y, NULL, NULL);
}

void
showCursor(void) {
	//el 2do parametro en 1 es show
	_syscall(VIDEO_CUR, 1, 0, 0, NULL, NULL);
}
void
hideCursor(void){
	//el 2do parametro en 0 es hide
	_syscall(VIDEO_CUR, 0, 0, 0, NULL, NULL);
}

void
videoAttr(char attr) {
	_syscall(VIDEO_ATTR, attr, 0, 0, NULL, NULL);
}

int
clear(void) {
	return _syscall(VIDEO_CLR, 0, 0, 0, NULL, NULL);
}

int
sleep(int segundos) {
	return _syscall(SLEEP, segundos, 0, 0, NULL, NULL);
}

int
mkdir(char * pathName, short int mode) {
	return _syscall(MKDIR, (int)mode, 0, 0, pathName, NULL);
}

int
opendir(char * pathName) {
	return _syscall(OPENDIR, 0, 0, 0, pathName, NULL);
}

void
closedir(int fd) {
	_syscall(CLOSEDIR, fd, 0, 0, NULL, NULL);
}

int
readdir(int fd, dirEntry * dirEnt) {
	return _syscall(READDIR, fd, 0, 0, (char*)dirEnt, NULL);
}

int
chdir(char * path) {
	return _syscall(CHDIR, 0, 0, 0, path, NULL);
}

char *
getcwd(char * name, int size) {
	return (char*)_syscall(GETCWD, size, 0, 0, name, NULL);
}

int
open(char * pathName, short int mode) {
	return _syscall(OPENFILE, mode, 0, 0, pathName, NULL);
}

void
close(int fd) {
	_syscall(CLOSEFILE, fd, 0, 0, NULL, NULL);
}

int
rename(const char * oldPath, const char * newPath) {
	return _syscall(RENAME, 0, 0, 0, (char*)oldPath, (char*)newPath);
}

int
rmdir(const char * path){
	//el segundo parametro en 0 es rmdir
	return _syscall(UNLINK, 0, 0, 0, (char*)path, NULL);
}

int
unlink(const char * path) {
	//el segundo parametro en 1 es unlink
	return _syscall(UNLINK, 1, 0, 0, (char*)path, NULL);
}

int
getFileSize(const char * path) {
	return _syscall(FILESIZE, 0, 0, 0, (char*)path, NULL);
}

